package pdfsetter.core.schema.advanced;

import java.util.ArrayList;
import java.util.List;

import pdfsetter.core.schema.FillingSchema;

/**
 * This is automatic version of {@link ConsecutiveFileListProcessPattern}. We select pages from every file in the same way and join them all procesiing each
 * file entirely, one by one, from first to last.
 * 
 * @author Andrzej Dorobisz
 */
public class AutomaticConsecutiveProcessPattern implements FillingSchemaPattern {
    private final FilePageSelector selector;

    public AutomaticConsecutiveProcessPattern(FilePageSelector selector) {
        this.selector = selector;
    }

    @Override
    public FillingSchema produceFillingSchema(int[] fileSizes) {
        List<AttachedFilePageSelector> attachedSelectors = new ArrayList<AttachedFilePageSelector>(fileSizes.length);
        for (int fileNum = 0; fileNum < fileSizes.length; fileNum++) {
            attachedSelectors.add(new AttachedFilePageSelector(selector, fileNum));
        }
        return new ConsecutiveFileListProcessPattern(attachedSelectors).produceFillingSchema(fileSizes);
    }

    @Override
    public int getExpectedNumberOfFiles() {
        return -1;
    }
}
